package com.fling.abcde.ui.citypicker.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.fling.abcde.R;

import java.util.ArrayList;
import java.util.List;

import static com.fling.abcde.BaseApplication.sContext;

/**
 * author zaaach on 2016/1/26.
 */
class HotCityGridAdapter extends BaseAdapter {

	private List<String> mCities;

	HotCityGridAdapter() {

		mCities = new ArrayList<>();
		mCities.add("北京");
		mCities.add("上海");
		mCities.add("广州");
		mCities.add("深圳");
		mCities.add("杭州");
		mCities.add("南京");
		mCities.add("天津");
		mCities.add("武汉");
		mCities.add("重庆");
	}

	@Override
	public int getCount() {

		return mCities == null ? 0 : mCities.size();
	}

	@Override
	public String getItem(int position) {

		return mCities == null ? null : mCities.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {

		HotCityViewHolder holder;
		if (view == null) {
			view = LayoutInflater.from(sContext).inflate(R.layout.cp_item_hot_city_gridview, parent, false);
			holder = new HotCityViewHolder();
			holder.name = (TextView) view.findViewById(R.id.tv_hot_city_name);
			view.setTag(holder);
		} else {
			holder = (HotCityViewHolder) view.getTag();
		}
		holder.name.setText(mCities.get(position));
		return view;
	}

	private static class HotCityViewHolder {

		TextView name;
	}
}
